package cn.NewsServlet;

import cn.NewsDao.NewsDao1;
import cn.NewsDaoImpl.NewsDaoImpl1;
import cn.entity.News1;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/system/newsupdate")
public class TianjiaServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String id = req.getParameter("id");
        String categoryId=req.getParameter("username");
        String title=req.getParameter("password");


        News1 news = new News1();
        news.setId(Integer.parseInt(id));
        news.setCategoryId(Integer.parseInt(categoryId));
        news.setTitle(title);
        NewsDao1 newsDao1 = new NewsDaoImpl1();
        PrintWriter printWriter=resp.getWriter();
        String rep = "";
        if(newsDao1.update(news)) {
            rep="1";

        }
        printWriter.println(rep);

        printWriter.flush();
        printWriter.close();
        /*if ( newsDao1.update(news)){
            req.getRequestDispatcher("index2.jsp");

        }else{
            System.out.println("修改失败");
        }*/
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("这是get方法");
    }
}
